home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / QuakeTools / src / util / light.c next >
Encoding:
C/C++ Source or Header  |  1998-06-11  |  4.4 KB  |  131 lines

  1. #define    LIBQTOOLS_CORE
  2. #define    LIBQBUILD_CORE
  3. #include <libqtools.h>
  4. #include <libqbuild.h>
  5.  
  6. struct memory bspStatic;
  7. struct memory *bspMem = &bspStatic;
  8.  
  9. extern int c_bad;
  10. extern struct tnode *tnodes, *tnode_p;
  11. extern bool *nolightface;
  12. extern float *minlights;
  13. extern float rangescale;
  14. extern float scalecos;
  15. extern float scaledist;
  16. extern int bspfileface;                        // next surface to dispatch
  17. extern vec3_t *faceoffset;
  18. extern vec3_t bsp_origin;
  19.  
  20. extern void LightWorld(__memBase);
  21. extern void MakeTnodes(__memBase, register struct dmodel_t * bm);
  22.  
  23. /*
  24.  * ========
  25.  * main
  26.  * 
  27.  * light modelfile
  28.  * ========
  29.  */
  30. int main(int argc, char **argv)
  31. {
  32.   int i;
  33.   char source[NAMELEN_PATH];
  34.   FILE *bspFile;
  35.   int litOptions = 0;
  36.  
  37.   memset(bspMem, 0, sizeof(struct memory));
  38.   if (!setjmp(eabort)) {
  39.     printf("----- LightFaces --------\n");
  40.  
  41.     for (i = 1; i < argc; i++) {
  42.       if (!strcmp(argv[i], "-extra")) {
  43.         litOptions |= LIGHT_EXTRA;
  44.         mprintf("extra sampling enabled\n");
  45.       }
  46.       else if (!strcmp(argv[i], "-rad")) {
  47.         litOptions |= LIGHT_RADIOSITY;
  48.         mprintf("radiosity calculation enabled\n");
  49.       }
  50.       else if (!strcmp(argv[i], "-waterlit")) {
  51.         litOptions |= LIGHT_WATERLIT;
  52.         mprintf("extra watershadowing enabled\n");
  53.       }
  54.       else if (!strcmp(argv[i], "-dist")) {
  55.         scaledist = atof(argv[i + 1]);
  56.         i++;
  57.       }
  58.       else if (!strcmp(argv[i], "-range")) {
  59.         rangescale = atof(argv[i + 1]);
  60.         i++;
  61.       }
  62.       else if (argv[i][0] == '-')
  63.         Error("Unknown option \"%s\"", argv[i]);
  64.       else
  65.         break;
  66.     }
  67.  
  68.     if (i != argc - 1)
  69.       Error("usage: light [-extra] bspfile");
  70.  
  71.     strcpy(source, argv[i]);
  72.     ReplaceExt(source, "bsp");
  73.     if((bspFile = fopen(source, READWRITE_BINARY_OLD))) {
  74.       bspMem = LoadBSP(bspFile, ALL_LUMPS & ~(LUMP_LIGHTING | LUMP_VISIBILITY));
  75.       bspMem->litOptions = litOptions;
  76.       AllocClusters(bspMem, LUMP_LIGHTING);
  77.     
  78.       if(!(minlights = (float *)kmalloc(sizeof(float) * bspMem->numfaces)))
  79.         Error("Light: failed to allocate minlights!\n");
  80.       if(!(nolightface = (bool *)kmalloc(sizeof(bool) * bspMem->numfaces)))
  81.         Error("Light: failed to allocate nolightface!\n");
  82.       if(!(faceoffset = (vec3_t *)kmalloc(sizeof(vec3_t) * bspMem->numfaces)))
  83.         Error("Light: failed to allocate faceoffset!\n");
  84.  
  85.       if(bspMem->litOptions & LIGHT_RADIOSITY) {
  86.         if(!(facepatches = (struct patch **)kmalloc(sizeof(struct patch *) * bspMem->numfaces)))
  87.           Error("Light: failed to allocate facepatches!\n");
  88.         if(!(faceentity = (struct entity **)kmalloc(sizeof(struct entity *) * bspMem->numfaces)))
  89.           Error("Light: failed to allocate faceentity!\n");
  90.         if(!(facelights = (struct facelight *)kmalloc(sizeof(struct entity *) * bspMem->numfaces)))
  91.           Error("Light: failed to allocate facelights!\n");
  92.         if(!(patches = (struct patch *)kmalloc(sizeof(struct patch) * 4096)))
  93.           Error("Light: failed to allocate patches!\n");
  94.         if(!(radiosity = (vec3_t *)kmalloc(sizeof(vec3_t) * bspMem->numfaces)))
  95.           Error("Light: failed to allocate radiosity!\n");
  96.         if(!(illumination = (vec3_t *)kmalloc(sizeof(vec3_t) * bspMem->numfaces)))
  97.           Error("Light: failed to allocate illumination!\n");
  98.         if(!(backplanes = (struct dplane_t *)kmalloc(sizeof(struct dplane_t) * bspMem->numplanes)))
  99.           Error("Light: failed to allocate backplanes!\n");
  100.         if(!(directlights = (struct directlight **)kmalloc(sizeof(struct directlight *) * bspMem->numleafs)))
  101.           Error("Light: failed to allocate directlights!\n");
  102.         if(!(leafparents = (int *)kmalloc(sizeof(int) * bspMem->numleafs)))
  103.           Error("Light: failed to allocate leafparents!\n");
  104.         if(!(nodeparents = (int *)kmalloc(sizeof(int) * bspMem->numnodes)))
  105.           Error("Light: failed to allocate nodeparents!\n");
  106.         if(!(texreflectivity = (vec3_t *)kmalloc(sizeof(vec3_t) * bspMem->numtexinfo)))
  107.           Error("Lights: failed to allocate texture reflectivity!\n");
  108.       }
  109.     
  110.       bspMem->mapOptions |= MAP_LOADLIGHTS;
  111.       LoadMapFile(bspMem, bspMem->dentdata);
  112.       MakeTnodes(bspMem, &bspMem->dmodels[0]);
  113.  
  114.       if(bspMem->litOptions & LIGHT_RADIOSITY)
  115.         RadWorld(bspMem);
  116.       else
  117.         LightWorld(bspMem);
  118.  
  119.       WriteEntitiesToString(bspMem);
  120.       WriteBSP(bspFile, bspMem);
  121.       PrintClusters(bspMem, 0, TRUE);
  122.       
  123.       FreeClusters(bspMem, 0);
  124.       kfree();
  125.       fclose(bspFile);
  126.     }
  127.   }
  128.  
  129.   return 0;
  130. }
  131.